package com.glsc.ngateway.platform.service.itflow.flowstrategy.cmdb.partIn.taskPostHandler;

import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.cmdb.CMDBPassParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.cmdb.CMDBRejectParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.cmdb.PartInTaskFormDto;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.cmdb.domainDto.FlowFormPartInDto;
import com.glsc.ngateway.common.api.flowable.resp.ResponseSituationDto;
import com.glsc.ngateway.common.base.enums.itflow.ITFlowTaskEnum;
import com.glsc.ngateway.platform.service.FlowCommonService;
import com.glsc.ngateway.platform.service.itflow.flowstrategy.cmdb.partIn.PartInFlowStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;

/**
 * @author zhengyr
 * @date 2023/8/2-16:16
 */
@Component
public class PIStep2LeaderTaskPostHandlerAudit implements IPartInTaskPostHandlerAudit {

    @Autowired
    PartInFlowStrategy partInFlowStrategy;
    @Autowired
    private FlowCommonService flowCommonService;
    @Autowired
    PIStepHandlerHelper handlerHelper;

    @Override
    public String getTaskDefinitionKey() {
        return ITFlowTaskEnum.CMDB_PART_IN_FLOW_LEADER_TASK.getTaskKey();
    }
    @Override
    public void passAfterHandle(@NotNull CMDBPassParamDto<FlowFormPartInDto, PartInTaskFormDto> passParam, @NotNull String operator) throws Exception {
        //如果流程未结束，通知下一个人
        ResponseSituationDto processInfo = flowCommonService.getProcessInfo(passParam.getProcessId());
        //发送邮件通知给下一个人
        FlowFormPartInDto formMainData = passParam.getFlowableFormData().getFormMainData();
        handlerHelper.notify(processInfo, formMainData.getProcessTitle(), formMainData.getFlowCreateOperatorName());
    }

    /**
     * 驳回后置处理方法
     */
    @Override
    public void rejectAfterHandle(@NotNull CMDBRejectParamDto param, @NotNull String operator) {
        handlerHelper.afterHandle(param, operator);
    }

}
